import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-21
 * Time: 22:46
 */
public class test1 {
    /*
    LeetCode 228 汇总区间
     */

    public List<String> summaryRanges(int[] nums) {
        List<String> ret = new ArrayList<>();
        StringBuilder str = new StringBuilder();
        if(nums.length==0){
            return ret;
        }
        boolean flag = false;
        for(int i=0;i<=nums.length-1;i++){
            str.append(nums[i]);
            while(i<nums.length-1 && nums[i+1]==nums[i]+1){
                i++;
                flag = true;
            }
            if(flag==true){
                str.append("->");
                str.append(nums[i]);
            }
            ret.add(String.valueOf(str));
            flag = false;
            str = new StringBuilder();
        }
        return ret;
    }
}
